<?php

header("utf-8");

class Users
{
	public $id;
	public $password;
	function __construct($a,$b) //获取账号密码
	{
		$this->id = $a;
		$this->password = $b;
	}
	public function show_information() //展示账号信息
	{
		echo "账号为："."$id"."<br>";
	}
	public function check() //检测用户信息
	{
		// 创建连接
		$con=mysqli_connect("localhost","root","","phptest");
		// 检测连接
		if (!$con) 
		{
			die("Connection failed: " . mysqli_connect_error());
		}
		else echo "Connected database successfully"."<br>";

		$result=mysqli_query($con,"SELECT password FROM user WHERE id='$this->id'");
		$local_code=mysqli_fetch_object($result);
		if($local_code==NULL)
			return 0;
		//echo $local_code->password."<br>"; 调试时使用的
		if($this->password==$local_code->password)
			return 1;
		else
			return 0;
	}
}


	$ID=$_POST["id"];
	$PASSWORD=$_POST["password"];
	if($PASSWORD==NULL)
		exit('输入为空，<a href="login(front).php">重试</a>');
	$PASSWORD_CODE=$PASSWORD;
	for($i = 0;$i<(int)(strlen($PASSWORD));$i++)
	{
		$PASSWORD_CODE[$i] = $PASSWORD[(strlen($PASSWORD))-$i-1];
	}

	$newuser = new Users($ID,$PASSWORD_CODE);
	if($newuser->check())
		echo "welcome"."<br>".$ID;
	else
		exit('验证失败，<a href="login(front).php">重试</a>');
	
?>